package com.javalong.androidmorning.wechat.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.javalong.androidmorning.common.util.XMLUtils;
import com.javalong.androidmorning.wechat.service.ResponseMessageService;

@Controller
@RequestMapping("wechat/")
public class WechartController {

	@Autowired
	private ResponseMessageService responseMessageService;

	@RequestMapping("msg")
	@ResponseBody
	public String wechatSendMsg(HttpServletRequest request) {
		try {
			Map<String, String> map = XMLUtils.parseRequestXml(request);
			String responseXml = responseMessageService.dealMessageMap(map);
			if (responseXml != null) {
				return responseXml;
			}
			return "";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

//	@RequestMapping("msg")
//	@ResponseBody
//	public String wechatSendMsg(@RequestParam("echostr") String echostr, HttpServletRequest request) {
//		return echostr;
//	}

}
